/*##############################################################################
################################################################################
##  
##                          MISC USEFUL FUNCTIONS
##
################################################################################
##############################################################################*/
// Takes a dictionary and updates the current one.
// NOTE THIS IS NOT RECURSIVE - perhaps it should be?
function _PTJS_update(target,dict) {
  for(var i in dict) {
    if(dict.hasOwnProperty(i)) {
      target[i] = dict[i];
    }
  }
  return target
}

function _PTJS_isEmpty(dict) {
  for(var i in dict) {
    if(dict.hasOwnProperty(i)) {
      if(typeof dict[i] != "function") {
        return false
      }
    }
  }
  return true
}

// generic enumerationFunction.prototype.forEach = function(object, block, context) {    for (var key in object) {        if (typeof this.prototype[key] == "undefined") {            block.call(context, object[key], key, object);        }    }};// globally resolve forEach enumerationvar forEach = function(object, block, context) {    if (object) {        var resolve = Object; // default        if (object instanceof Function) {            // functions have a "length" property            resolve = Function;        } else if (object.forEach instanceof Function) {            // the object implements a custom forEach method so use that            object.forEach(block, context);            return;        } else if (typeof object.length == "number") {            // the object is array-like            resolve = Array;        }        resolve.forEach(object, block, context);    }};

// To help print objects
var tostring = function(context,val,key,object) {
  alert(key + ":" + val);
}

// To make Arrays better
Array.prototype.index = function(thing) {
  for(var i=0;i<this.length;i++) {
    if(this[i] == thing) {
    return i;
    }
  }
  return false
}
Array.prototype.remove = function(thing) {
  for(var i=0;i<this.length;i++) {
    if(this[i] == thing) {
      this.splice(i,1);
      return true
    }
  }
  return false
}
Array.prototype.pushUnique = function(thing) {
  for(var i=0;i<this.length;i++) {
    if(this[i] == thing) {
      return false;
    }
  }
  this.push(thing)
  return true;
}
